/**
 * @file fibonacci.cpp
 * @brief 斐波那契数列
 * @author Xavier ZXY (zxy_xavier@163.com)
 * @version : 1.0
 * @date 2022-05-01
 * 
 */
#include <iostream>
#include <stdio.h>

using namespace std;

/**
 * @brief 斐波那契的递归函数
 * @param  i                 
 * @return int 
 */
int Fbi(int i) {
    if (i < 2)
        return i == 0 ? 0 : 1;
    return Fbi(i - 1) + Fbi(i - 2);
}

int main(int argc, char const *argv[])
{
    printf("迭代显示斐波那契数列: \n");
    int a[40];
    a[0] = 0;
    a[1] = 1;
    cout << a[0] << " " << a[1];
    for (int i = 2; i < 40; i ++) {
        a[i] = a[i - 1] + a[i - 2];
        cout << a[i] << " ";
    }

    cout << "递归显示斐波那契数列:" << endl;
    for (int i = 0; i < 40; i ++) {
        cout << Fbi(i) << " ";
    }

    return 0;
}
